#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-08-10 8:37 上午
# @Author  : yangdy
# @File    : 2020-08-10.696.计数二进制子串
# @Software: PyCharmCE
from tools.my_methods import *


class Solution:
    def countBinarySubstrings(self, s: str) -> int:
        ans = 0
        if not s:
            return ans
        ls = len(s)
        cs = []
        c = 1
        si = s[0]
        for i in range(1, ls):
            if s[i] == si:
                c += 1
            else:
                cs.append(c)
                c = 1
                si = s[i]
        cs.append(c)
        for i in range(1, len(cs)):
            ans += min(cs[i], cs[i-1])

        return ans


questions = [
    ('00110011',),
    ('10101',),
]

work(questions, lambda q: Solution().countBinarySubstrings(q[0]))
